﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WpfApplication1.Controls;
using System.Windows.Threading;

namespace WpfApplication1.Utils
{
    class AnnouncementSystem
    {
        static List<WindowAnnouncement> listwnd = new List<WindowAnnouncement>();
        DispatcherTimer timer = new DispatcherTimer();
        public AnnouncementSystem()
        {
            timer.Tick += new EventHandler((sender, ex) => DeleteAnnounment());
            timer.Interval = new TimeSpan(0, 0, 5);
        }

        public void AddAnnounment(string message)
        {
            try
            {
                if (listwnd.Count == 0)
                {
                    timer.Start();
                }
                long temp_height = 30; //55
                for (int i = 0; i < listwnd.Count; i++)
                    temp_height += listwnd[i].GridHeight + 10;
                WindowAnnouncement wnd = new WindowAnnouncement(message, 720, temp_height);
                wnd.DoMoveDown = (long di) => SortAgain(di);
                wnd.Show();
                wnd.Top -= wnd.GridHeight;
                listwnd.Add(wnd);
            }
            catch 
            {
                return;
            }
           
        }

        public void DeleteAnnounment()
        {
            if (listwnd.Count != 0)
            {
                listwnd[0].HideWindow();
                listwnd.RemoveAt(0);
            }
            else
                timer.Stop();

        }

        public void SortAgain(long di)
        {
            for (int i = 0; i < listwnd.Count; i++)
            {
                listwnd[i].MoveDown(di);
            }
        }
    }
}
